home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 2: Applications / Linux Cubed Series 2 - Applications.iso / circuits / irsim-ca.2 / irsim-ca / irsim-cap-9.2 / src / other / inet2sim / Sim.c < prev   
C/C++ Source or Header  |  1991-03-14  |  6KB  |  237 lines

  1. /* 
  2.  *     ********************************************************************* 
  3.  *     * Copyright (C) 1988, 1990 Stanford University.                     * 
  4.  *     * Permission to use, copy, modify, and distribute this              * 
  5.  *     * software and its documentation for any purpose and without        * 
  6.  *     * fee is hereby granted, provided that the above copyright          * 
  7.  *     * notice appear in all copies.  Stanford University                 * 
  8.  *     * makes no representations about the suitability of this            * 
  9.  *     * software for any purpose.  It is provided "as is" without         * 
  10.  *     * express or implied warranty.  Export of this software outside     * 
  11.  *     * of the United States of America may require an export license.    * 
  12.  *     ********************************************************************* 
  13.  */
  14.  
  15. #include <stdio.h>
  16. #include "defs.h"
  17. #include "net.h"
  18. #include "globals.h"
  19. #include "net_macros.h"
  20.  
  21.  
  22. public    nptr   VDD_node;        /* power supply nodes */
  23. public    nptr   GND_node;
  24.  
  25. public    lptr   on_trans;        /* always on transistors */
  26.  
  27. public    int    nnodes;            /* number of actual nodes */
  28. public    int    naliases;        /* number of aliased nodes */
  29. public    int    ntrans[ NTTYPES ];    /* number of txtors indexed by type */
  30.  
  31. public    lptr   freeLinks = NULL;    /* free list of Tlist structs */
  32. public    tptr   freeTrans = NULL;    /* free list of Transistor structs */
  33. public    nptr   freeNodes = NULL;    /* free list of Node structs */
  34.  
  35. public    tptr   tcap = NULL;        /* list of capacitor-transistors */
  36.  
  37.  
  38. public
  39. #define    MIN_CAP        0.0005        /* minimum node capacitance (in pf) */
  40.  
  41.  
  42. private void init_counts()
  43.   {
  44.     register int  i;
  45.  
  46.     for( i = 0; i < NTTYPES; i++ )
  47.     ntrans[i] = 0;
  48.     nnodes = naliases = 0;
  49.   }
  50.  
  51.  
  52. public int rd_network( simfile )
  53.   FILE  *simfile;
  54.   {
  55.     static int  firstcall = 1;
  56.     char        line[ 200 ];
  57.  
  58.     if( firstcall )
  59.       {
  60.     init_hash();
  61.     init_counts();
  62.     init_listTbl();
  63.  
  64.     VDD_node = GetNode( "Vdd" );
  65.     VDD_node->npot = HIGH;
  66.     VDD_node->nflags |= (INPUT | POWER_RAIL);
  67.     VDD_node->head.inp = 1;
  68.     VDD_node->head.val = HIGH;
  69.     VDD_node->head.punt = 0;
  70.     VDD_node->head.time = 0;
  71.     VDD_node->head.t.r.rtime = VDD_node->head.t.r.delay = 0;
  72.     VDD_node->head.next = last_hist;
  73.     VDD_node->curr = &(VDD_node->head);
  74.  
  75.     GND_node = GetNode( "Gnd" );
  76.     GND_node->npot = LOW;
  77.     GND_node->nflags |= (INPUT | POWER_RAIL);
  78.     GND_node->head.inp = 1;
  79.     GND_node->head.val = LOW;
  80.     GND_node->head.punt = 0;
  81.     GND_node->head.time = 0;
  82.     GND_node->head.t.r.rtime = GND_node->head.t.r.delay = 0;
  83.     GND_node->head.next = last_hist;
  84.     GND_node->curr = &(GND_node->head);
  85.  
  86.     NEW_TRANS( tcap );
  87.     tcap->scache.t = tcap->dcache.t = tcap;
  88.     tcap->x.pos = 0;
  89.  
  90.     firstcall = 0;
  91.       }
  92.  
  93.     if( fgetline( line, 200, simfile ) == NULL )
  94.       {
  95.     lprintf( stderr, "can't read input file\n" );
  96.     exit( 1 );
  97.       }
  98.     if( rd_netfile( simfile, line ) == FALSE )
  99.     exit( 1 );
  100.   }
  101.  
  102.  
  103. public void pTotalNodes()
  104.   {
  105.     lprintf( stdout, "%d nodes", nnodes );
  106.     if( naliases != 0 )
  107.     lprintf( stdout, ", %d aliases", naliases );
  108.     lprintf( stdout, "; " );
  109.   }
  110.  
  111.  
  112. public void pTotalTxtors()
  113.   {
  114.     int  i;
  115.  
  116.     lprintf( stdout, "transistors:" );
  117.     for( i = 0; i < NTTYPES; i++ )
  118.     if( ntrans[i] != 0 )
  119.         lprintf( stdout, " %s=%d", ttype[i], ntrans[i] );
  120.     if( tcap->x.pos != 0 )
  121.     lprintf( stdout, " shorted=%d", tcap->x.pos );
  122.     lprintf( stdout, "\n" );
  123.   }
  124.  
  125.  
  126. public void ConnectNetwork()
  127.   {
  128. #ifdef notdef
  129.     nptr  ndlist;
  130.  
  131.     pTotalNodes();
  132.     ndlist = ( isBinFile ) ? bin_connect_txtors() : connect_txtors();
  133.     pTotalTxtors();
  134.     make_parallel( ndlist, (long)(stack_txtors ? 0 : VISITED) );
  135.     pParallelTxtors();
  136.     if( stack_txtors )
  137.       {
  138.     make_stacks( ndlist );
  139.     pStackedTxtors();
  140.       }
  141. #endif
  142.   }
  143.  
  144.  
  145. #define    SIZE2LAMBDA( X )    ( (double) (X) / LAMBDACM )
  146. #define    CAP_LIM            ( 2 * MIN_CAP )
  147. #define    CAP2FF( C )        ( (int) (((C) + (MIN_CAP / 2)) * 1000.0) )
  148.  
  149.  
  150. public void wr_sim( fout )
  151.   FILE  *fout;
  152.   {
  153.     register tptr  t;
  154.     register nptr  n;
  155.     tptr           tlist;
  156.     nptr           nlist;
  157.     char           capfmt[50];
  158.  
  159.     if( use_GND and GND_node->nname[0] == 'G' )        /* may be a number */
  160.     (void) strcpy( GND_node->nname, "GND" );
  161.  
  162.     nlist = GetNodeList();
  163.     GetInetParms( &tlist, &LAMBDACM );
  164.  
  165.     for( t = tlist; t != NULL; t = t->scache.t )
  166.       {
  167.     int  type;
  168.  
  169.     type = BASETYPE( t->ttype );
  170.  
  171.     if( type == RESIST )
  172.       {
  173.         (void) fprintf( fout, "r %s %s %.2f\n",
  174.           pnode( t->source ), pnode( t->drain ), t->r->rstatic );
  175.       }
  176.     else
  177.       {
  178.         (void) fprintf( fout, "%c %s %s %s %.2f %.2f", ttype[type][0],
  179.           pnode( t->gate ), pnode( t->source ), pnode( t->drain ),
  180.           SIZE2LAMBDA( t->r->length ), SIZE2LAMBDA( t->r->width ) );
  181.         if( t->tlink != t )
  182.         (void) fprintf( fout, " %ld %ld", t->x, t->y );
  183.         (void) fputc( '\n', fout );
  184.       }
  185.     t->gate->nflags |= VISITED;
  186.     t->source->nflags |= VISITED;
  187.     t->drain->nflags |= VISITED;
  188.       }
  189.  
  190.     if( do_sim_cap and two_term_caps )
  191.       {
  192.     (void) sprintf( capfmt, "C %%s %s %%d\n", GND_node->nname );
  193.  
  194.     for( n = nlist; n != NULL; n = n->n.next )
  195.       {
  196.         if( not (n->nflags & VISITED) or n->ncap >= CAP_LIM )
  197.         (void) fprintf( fout, capfmt, pnode( n ), CAP2FF( n->ncap ) );
  198.       }
  199.       }
  200.     else if( do_sim_cap )
  201.       {
  202.     for( n = nlist; n != NULL; n = n->n.next )
  203.       {
  204.         if( not (n->nflags & VISITED) or n->ncap >= CAP_LIM )
  205.         (void) fprintf( fout, "C %s %.3f\n", pnode( n ), n->ncap );
  206.       }
  207.      }
  208.  
  209.     for( n = nlist; n != NULL; n = n->n.next )
  210.       {
  211.     if( n->nflags & ALIAS )
  212.         (void) fprintf( fout, "= %s %s\n", pnode( n ), pnode( n->nlink ));
  213.       }
  214.  
  215.     if( do_delays )
  216.       {
  217.     for( n = nlist; n != NULL; n = n->n.next )
  218.       {
  219.         if( n->nflags & USERDELAY )
  220.         (void) fprintf( fout, "D %s %.2f %.2f\n", pnode( n ),
  221.           d2ns( n->tplh ), d2ns( n->tphl ) );
  222.       }
  223.       }
  224.  
  225.     if( do_thresholds )
  226.       {
  227.     float  vhigh = HIGHTHRESH, vlow = LOWTHRESH;
  228.  
  229.     for( n = nlist; n != NULL; n = n->n.next )
  230.       {
  231.         if( n->vlow != vlow or n->vhigh != vhigh )
  232.         (void) fprintf( fout, "t %s %g %g\n", pnode( n ),
  233.           n->vlow, n->vhigh );
  234.       }
  235.       }
  236.   }
  237.